import math
import cmath
from scipy.integrate import quad
import numpy
from constant import *




def bath_response_function(T, t, J, parameters):
        r = quad(lambda w: (J(w, parameters) / math.tanh(0.5 * hbar * w / (k * T))) * math.cos(w * t) / PI, 0, 50 * parameters[-1], limit = 100000)
        i = quad(lambda w: -1.0 * J(w, parameters) * math.sin(w * t) / PI, 0, 50 * parameters[-1], limit = 100000)
        return [r[0], i[0]]


def Feyman_Vernon_Specific_Distance_Contribution(T, J, stepsize, parameters, kmax, sk_plus, sk_minus, skdelta_plus, skdelta_minus):
        ret = bath_response_function(T, kmax * stepsize, J, parameters)
	bath_resp_ret = complex(ret[0], ret[1])
        return cmath.exp(-(skdelta_plus - skdelta_minus) * (bath_resp_ret * sk_plus - bath_resp_ret.conjugate() * sk_minus) * stepsize * stepsize / hbar)
